/**
 * 
 */
package com.epro.dx.enable;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.weipu.common.util.Logger;
import com.weipu.common.util.NetWorkUtil;

/**
 * 网络监听广播
 * @version [版本号, 2013-9-22]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 * 
 * @author dc051
 */
public class NetworkBroadcastReceiver extends BroadcastReceiver
{
    static String TAG = "NetworkBroadcastReceiver";
    
    private static NetWorkCallBack mCallBack;
    
    public static void setCallBack(NetWorkCallBack callback)
    {
        mCallBack = callback;
    }
    
    @Override
    public void onReceive(Context context, Intent intent)
    {
        // 检测网络
        boolean isNetAvaliable = NetWorkUtil.isNetworkAvailable(context);
        Logger.i(TAG, "network is available is " + isNetAvaliable);
        if (null != mCallBack)
        {
            //设置回调
            mCallBack.netWorkChangeCallBack(isNetAvaliable);
        }
        
    }
    
    /**
     * 网络变化接口
     * 
     * @author  hjd008
     * @version  [版本号, 2014-12-23]
     * @see  [相关类/方法]
     * @since  [产品/模块版本]
     */
    public interface NetWorkCallBack
    {
        /**  
         * 网络状态变化接口
         * @param isNetAvailable 网络是否可用
         * @see [类、类#方法、类#成员]
         */
        void netWorkChangeCallBack(boolean isNetAvaliable);
    }
    
}
